#include "zlog.h"
#include <stdint.h>

unsigned char xor_CHECK(unsigned char *addr, unsigned int Len)
{

    uint8_t xorval = 0;
    for (int i = 1; i < Len - 2; i++)
    {
        xorval ^= addr[i];
    }
    return xorval;
}

int main()
{
    // DD 54 C7 23 13 02 39 39 39 33 37 35 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 01 00 01 60 02 05 00 00 01 00 02 00 02 01 E0 00 00 00 01 00 00 12 21 00 00 00 34 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 BB
    uint8_t buff[] = {0xDD, 0x54, 0xC7, 0x23, 0x13, 0x02, 0x39, 0x39, 0x39, 0x33, 0x37, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x60, 0x02, 0x05, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x02, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x12, 0x21, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0xBB};
    uint8_t xorval = xor_CHECK(buff, sizeof(buff) - 2);
    printf("xorval: 0x%02x\n", xorval);
    // 初始化 zlog
    if (zlog_init("zlog.conf"))
    {
        printf("zlog init failed\n");
        return -1;
    }

    // 获取分类
    zlog_category_t *c_recv = zlog_get_category("recv");
    zlog_category_t *c_send = zlog_get_category("send");
    zlog_category_t *c_send_recv = zlog_get_category("send-recv");
    zlog_category_t *c_C1_main = zlog_get_category("C1_main");     // C1_ 的子分类
    zlog_category_t *c_C2_sensor = zlog_get_category("C2_sensor"); // C2_ 的子分类

    // 写日志
    zlog_fatal(c_recv, "zlog_fatal");
    zlog_info(c_recv, "zlog_info Received data from client");
    zlog_debug(c_send, "zlog_debug Sending packet %d", 1001);
    zlog_error(c_send_recv, "zlog_error Send-Recv buffer overflow");
    zlog_warn(c_C1_main, "zlog_warn Device C1 temperature is high");
    zlog_info(c_C2_sensor, "zlog_info Sensor data: %.2f", 23.5);

    zlog_notice(c_C2_sensor, "zlog_notice Sensor data: %.2f", 23.5);

    char buf[8] = {1, 2, 3, 4, 5, 6, 7, 8};
    hzlog_info(c_recv, buf, 8);

    // 清理
    zlog_fini();
    return 0;
}